using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace Nizm0.QOT.Panels
{
    public partial class PropertyWindow : ToolWindow
    {
        public PropertyWindow()
        {
            InitializeComponent();
			comboBox.SelectedIndex = 0;
			//propertyGrid.SelectedObject = propertyGrid;
        }

        public PropertyWindow(Object obj)
        {
            InitializeComponent();
            comboBox.SelectedIndex = 0;
            propertyGrid.SelectedObject = obj;
        }
        private Object _selectedObjectParent;
        public Object SelectedObjectParent { 
            get 
            { 
                return _selectedObjectParent; 
            }
            set
            {
                _selectedObjectParent = value;
                comboBox.Items.Clear();
            }
        }
        public Object SelectedObject
        {
            get { return propertyGrid.SelectedObject; }
            set
            {
                if (value != null)
                {
                    propertyGrid.SelectedObject = value;
                    //this.TabText = "Property - " + value.ToString();
                    //if (!comboBox.Items.Contains(value))
                    //    comboBox.Items.Add(value);
                    if (value.GetType().IsSubclassOf(typeof(Form)))
                    {
                        comboBox.Items.Clear();
                        comboBox.Items.Add(value);
                        foreach (object obj in ((Form)value).Controls)
                            comboBox.Items.Add(obj);
                    }
                    comboBox.SelectedItem = value;
                }
                else
                {
                    propertyGrid.SelectedObject = null;
                    comboBox.Items.Clear();
                }
            }
        }

        private void PropertyWindow_Activated(object sender, EventArgs e)
        {
            propertyGrid.Refresh();
        }

        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            propertyGrid.SelectedObject = comboBox.SelectedItem;
            //this.TabText = "Property - " + comboBox.SelectedItem.ToString();
        }
    }
}